<?php

/**
* alltosun.com 文件控制器 index.php
* ============================================================================
* 版权所有 (C) 2009-2014 北京互动阳光科技有限公司，并保留所有权利。
* 网站地址: http://www.alltosun.com
* ----------------------------------------------------------------------------
* 许可声明: 这是一个开源程序，未经许可不得将本软件的整体或任何部分用于商业用途及再发布。
* ============================================================================
* $Author: 钱有明 (qianym@alltosun.com) $
* $Date: 2014-7-15 下午2:39:02 $
* $Id$
*/

class Action
{
    /**
     * 下载微博附件
     */
    public function t_file()
    {
        $file_path = trim(AnFilter::filter_string(Request::getParam('file_path')));
        $title     = trim(AnFilter::filter_string(Request::getParam('file_title')));

        if (!$file_path) {
            exit('');
        }

        $real_file_path = UPLOAD_PATH.$file_path;
        $file_extension_name = pathinfo($real_file_path, PATHINFO_EXTENSION);
        $name = $title ? $title : date('Y-m-d');
        if (strpos($name, $file_extension_name) == false) {
            $name .= $file_extension_name;
        }

        header('Content-Description: File Transfer');
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename='.$name);
        header('Content-Transfer-Encoding: binary');
        header('Expires: 0');
        header('Cache-Control: must-revalidate');
        header('Pragma: public');
        header('Content-Length: ' . filesize($real_file_path));
        ob_clean();
        flush();
        readfile($real_file_path);
        exit;
    }
}
?>